<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>商家后台首页</title>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="stylesheet" type="text/css" href="__MERCHANT_STATIC__/hui/static/h-ui/css/H-ui.min.css" />
  <link rel="stylesheet" type="text/css" href="__MERCHANT_STATIC__/hui/static/h-ui.admin/css/H-ui.admin.css" />
  <link rel="stylesheet" type="text/css" href="__MERCHANT_STATIC__/hui/lib/Hui-iconfont/1.0.8/iconfont.css" />
  <link rel="stylesheet" type="text/css" href="__MERCHANT_STATIC__/hui/static/h-ui.admin/skin/default/skin.css" id="skin" />
  <link rel="stylesheet" type="text/css" href="__MERCHANT_STATIC__/hui/static/h-ui.admin/css/style.css" />
  <link rel="stylesheet" href="__MERCHANT_STATIC__/style/css/h-ui/css/H-ui.min.css">
  <link rel="stylesheet" href="__MERCHANT_STATIC__/style/css/page.css">
  <link rel="stylesheet" href="__MERCHANT_STATIC__/style/css/public.css">
  <link rel="stylesheet" href="__MERCHANT_STATIC__/style/css/style.css">
  <link rel="stylesheet" href="__MERCHANT_STATIC__/style/css/styled.css"/>
 
  <style>
    a {
      color: #000;
    }
    a:hover{
      color: #000;
    }
    .dropDown {
      margin: 18px 31px 0 0;
    }
    .margin {
      margin-left: 50px;
    }
    ul li {
      cursor: pointer;
    }
    .actives {
      background:#43b9ec;
      color: #fff;
    }
  </style>
</head> 
<body>
{include file="common/header" /}
{include file="common/menu" /}
<div class="dislpayArrow hidden-xs"><a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a></div>

<div class="Hui-article-box" style="margin-top: 37px;">
	<div class="breadcrumb"><i class="Hui-iconfont"></i>商品
	<span class="c-gray en">&gt;</span> 添加商品
	<span class="c-gray en">&gt;</span> 选择商品分类<span class="c-gray en">&gt;</span> 
	</div>
	<div class="Hui-article">
			<ul class="hui-title cl">
				<li style="background: #43c9eb;color: #fff;">选择商品分类</li>
				<li>编辑基本信息</li>
			</ul>
			<div class="contains">
	<!--商品分类-->
    <div class="wareSort clearfix">
		<ul id="sort1">
			{foreach($data as $k => $v)}
			<li onclick="findChild({$v['goods_category_id']})">{$v['goods_category_name']}</li>
			{/foreach}
		</ul>
		<ul id="sort2" style="display: none;">
		</ul>
		<ul id="sort3" style="display: none;">
		</ul>
	</div>
	<div class="selectedSort"><b>您当前选择的商品类别是：<span class="s1"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="s3"></span></b><i id="selectedSort"></i></div>
	<div class="wareSortBtn" style="margin-top: 20px;">
		<button class="btn xia">下一步</button>
	</div>
</div>
	</div>
</div>
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/static/h-ui.admin/js/H-ui.admin.page.js"></script> 
<script type="text/javascript" src="__MERCHANT_STATIC__/style/js/page.js"></script> 
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__MERCHANT_STATIC__/hui/lib/laypage/1.2/laypage.js"></script>

<script type="text/javascript">
	/*function addCookie(key,value,day){
		var date=new Date();//创建日期对象
		date.setDate(date.getDate()+day);//过期时间：获取当前的日期+天数，设置给date
		document.cookie=key+'='+encodeURI(value)+';expires='+date;//添加cookie，设置过期时间
	};*/
	function readCookie (name)
    {
        var cookieValue = "";
        var search = name + "=";
        if (document.cookie.length > 0)
        {
            offset = document.cookie.indexOf (search);
            if (offset != -1)
            {
                offset += search.length;
                end = document.cookie.indexOf (";", offset);
                if (end == -1)
                    end = document.cookie.length;
                cookieValue = unescape (document.cookie.substring (offset, end))
            }
        }
        return cookieValue;
    }
    function writeCookie (name, value, hours)
    {
        var expire = "";
        if (hours != null)
        {
            expire = new Date ((new Date ()).getTime () + hours * 3600000);
            expire = "; expires=" + expire.toGMTString ();
        }
        document.cookie = name + "=" + escape (value) + expire;
    }
	$('#sort1').on('click',function(){
		$('#sort2').show();
		$('#sort3').hide();
	})
	$('#sort1').children('li').on('click',function(){
        $(this).addClass('actives').siblings().removeClass('actives');
        var value1=$(this).html();
        $('.s1').html(value1);
    })
	$('#sort2').on('click',function(){
		$('#sort3').show();
	})
</script>
<script type="text/javascript">

function findChild(catId){
	$.ajax({
          type: "get",
          url: "<?php echo url('goodscategory/childs', '', false); ?>/catId/" + catId, 
          dataType: 'json',
          cache: false,
     
          success: function(data) {
          	var str = '';
            if(data.status == 1) 
            {
            	$(data.data).each(function(k, v)
            	{
            		str += '<li onclick="findSubChild('+v.goods_category_id+')">'+v.goods_category_name+'</li>';
            	});
              $('#sort2').html(str);
              $('#sort2').children('li').on('click',function(){
              	$(this).addClass('actives').siblings().removeClass('actives');
              	var value2=$(this).html();
              	$('.s2').html(value2);
              })
            }else{
              layer.msg(data.msg);
            }

          },
          error: function(xhr, status, error) {
            console.log(xhr);
            console.log(status);
            console.log(error);
          }
    });
}



function findSubChild(catId){
	$.ajax({
          type: "get",
          url: "<?php echo url('goodscategory/childs', '', false); ?>/catId/" + catId, 
          dataType: 'json',
          cache: false,
     
          success: function(data) {
          	var str = '';
          	var stu=[];
            if(data.status == 1) 
            {
            	$(data.data).each(function(k, v)
            	{
            		str += '<li>'+v.goods_category_name+'</li>';
            		stu.push(v.goods_category_id);
            	});
              	$('#sort3').html(str);
                $('#sort3').children('li').on('click',function(){
              		$(this).addClass('actives').siblings().removeClass('actives');
              		var value3=$(this).html();
              		$('.s3').html(value3);
              		var num=$(this).index();
              		var id=stu[num];
              		 writeCookie ("id", id );
              	})
            }else{
              layer.msg(data.msg);
            }

          },
          error: function(xhr, status, error) {
            console.log(xhr);
            console.log(status);
            console.log(error);
          }
    });
}
$('.xia').on('click',function(){
   	var id=readCookie ("id")
   $.ajax({
    	type: "post",
        url: "<?php echo url('goods/insert', '', false); ?>/catId/" + id, 
        dataType: 'json',
        cache: false,
        success: function(data) {
            var str = '';
            if(data.status == 1) {
              	location.href = "{:url('goods/update', '', false)}/goodsId/" + data.data.id + '/catId/' + data.data.catId;		            	
            }else{
              	layer.msg(data.msg);
            }

        },
        error: function(xhr, status, error) {
            console.log(xhr);
            console.log(status);
            console.log(error);
        }
    });
})

</script>
 </body>
</html>


